package cn.xutongxue.gateway.security;

import cn.dev33.satoken.stp.StpInterface;
import cn.xutongxue.api.client.UserClient;
import com.alibaba.cloud.commons.lang.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 自定义权限验证接口扩展 
 */
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private UserClient userClient;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 返回此 loginId 拥有的权限列表 
        return Collections.emptyList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 返回此 loginId 拥有的角色列表
        String userRole = userClient.getUserRole(Integer.parseInt(loginId.toString()));
        if (StringUtils.isBlank(userRole)) {
            return Collections.emptyList();
        }
        return List.of(userRole);
    }

}
